// pages/editNote/editNote.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var _orderid = options.orderId;
    var that = this;
    wx.request({
      url: app.globalData.ip + '/api/order/' + _orderid,
      method: "GET",
      header:{
        "X-Token":app.globalData.token
      },
      success: e => {
        var orderJson = e.data.data;
        // console.log(e);
        // console.log(orderJson);
        var _createTime = app.timeFormat(orderJson.orderEntity.createTime);
        that.setData({
          dishesArray: orderJson.list,
          orderId: orderJson.orderEntity.id,
          time: _createTime,
          money: orderJson.orderEntity.totalAmount,
        })
      }
    })
  },
  contentInput: function(e) {
    console.log(e);
    this.setData({
      content: e.detail.value
    })
  },
  postComment: function(e) {
    var _comment = this.data.content;
    var _orderid = this.data.orderId;
    console.log("fuck comment");
    console.log(_orderid);
    wx.request({
      url: app.globalData.ip + '/api/comment',
      method: "POST",
      header: {
        "X-Token": app.globalData.token
      },
      //打你哦 都和你说了 还不改
      data:{
        content:_comment,
        orderId:_orderid,
        praise:0
      },

      success: e => {
        var page = getCurrentPages().pop();
        if (page == null || page == undefined) {
          return;
        } 
        page.onShow();
        wx.switchTab({
          url: '../index/index',
        })
      }
    })
  },
  toOrderDetail:function(){
    wx.navigateTo({
      url: '../orderDetail/orderDetail?orderId=' + this.data.orderId,
    })
  }
})